package zuoye.zy1;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.NodeList;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@Slf4j
public class Test {
    public static void main(String[] args) throws DocumentException {
        log.info("开始解析 XML 文件并加载 User 数据...");
        Map<Integer,User> map = new HashMap<>();
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("D:\\javabase_ws\\javaAdvanceProject\\day12_properties_xml_log\\src\\zuoye\\zy1\\users.xml");
        Element root = read.getRootElement();

        // 遍历所有 <User> 节点
        for (Element user : root.elements("user")) {
            map.put(Integer.parseInt(user.attributeValue("id")), new User(user.elementText("name"), user.elementText("sex"), user.elementText("地址"), user.elementText("password")));
        }

        // 打印结果
      map.forEach((k,v)->{
          System.out.println(k+"---"+v);
          log.info("输出结果 -> key=" + k + ", value=" + v);
      });
    }
}

